<template>
	<div >
		
		<el-row :gutter="10">
		  <el-col :span="5"><el-input  v-model="search.customerName" placeholder="请输入要查询的姓名"></el-input></el-col>
		  <el-col :span="6">
		    <el-button type="primary" icon="el-icon-search" @click="searchData()">搜索</el-button>
		    <el-button type="primary" icon="el-icon-circle-plus-outline"  plain @click="add()" >添加</el-button>
		  </el-col>
		</el-row>
		<el-table :data="result.tableData" style="width: 100%">
			<el-table-column label="序号" prop="bedId" width="48px"></el-table-column>

			<el-table-column label="档案编号" prop="recordId" width="150px"></el-table-column>

			<el-table-column label="姓名" prop="customerName" width="70px"></el-table-column>

			<el-table-column label="客户id" prop="customerId" width="65px"></el-table-column>

			<el-table-column label="性别" prop="customerGender" width="48px"></el-table-column>

			<el-table-column label="床位状态" prop="bedStatus" width="80px"></el-table-column>

			<el-table-column label="床位使用起始日期" prop="bedSdate" width="140px"></el-table-column>

			<el-table-column label="床位使用结束日期	" prop="bedEdate" width="140px"></el-table-column>

			<el-table-column label="床位详细信息	" prop="bedInfo" width="130px"></el-table-column>

			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="mini"  @click="handleEdit(scope.row.bedId)">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.row.bedId)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		
		<el-pagination style="margin-top:20px;" background layout="prev, pager, next"
				 :total="result.total"
				 :current-page.sync="query.current" :page-size="query.size" @current-change="getData()">
		</el-pagination>
		
		<el-dialog :title="title" :visible.sync="show">
			
			<BedAdd :show.sync="show" @getData="getData" :editid="editid" :key="showNum"></BedAdd>
			
		</el-dialog>
	</div>
</template>
<script>
import axios from '@/utils/axiosutils.js';
import BedAdd from "./bed_add.vue";
export default {
	data() {
		return {
			search: {
			  customerName: ''
			},
			query: {
			  customerName: '',
			  current: 1,
			  size: 10
			},
			result:{
			  tableData: [],
			  pages: 0
			},
			showNum: 0,
			show: false,
			editid: null,
			title: ''
		};
	},
	components:{
		BedAdd
	},
	created() {
		this.getData();
	},
	methods: {
		getData() {
			axios.get(
				'/bed/list',
				resp => {
					let page = resp.obj;
					this.result.tableData = page.records
					this.result.total = page.total;
				},
				this.query
			);
		},
		searchData() {
		  this.query.customerName = this.search.customerName
		  this.query.current = 1
		  this.getData()
		},
		add(){
		  this.showNum++;
		  this.title = '添加用户'
		  this.editid = null
		  this.show = true
		},
		handleEdit(bedId) {
		this.showNum++;
		  this.title = '修改用户'
		  this.editid = bedId
		  this.show = true
		},
		handleDelete(bedId) {
		      axios.del('/bed/del',response => {
		        this.getData()	
		      },{ bedId: bedId })
		    }
	}
};
</script>

<style>
	.el-row{
		height: 50px;
	}
.el-main {
	background-color: #e9eef3;
	color: #333;
	line-height: 20px !important;
}
</style>
